package com.caojing.syby.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.caojing.syby.R;
import com.caojing.syby.bean.search.ClasslyBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/9/1.
 */
public class ShowAdapter extends BaseAdapter {
    private List<ClasslyBean> list;

    public ShowAdapter(List<ClasslyBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_activity_gv_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.searchActivityGvItemTv.setText(list.get(position).getName());
        holder.searchActivityGvItemIv.setImageResource(list.get(position).getImage());
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.search_activity_gv_item_iv)
        ImageView searchActivityGvItemIv;
        @Bind(R.id.search_activity_gv_item_tv)
        TextView searchActivityGvItemTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
